package jfprincesstests.fakes;

import jfuzzyprincepless.agents.BaseNegotiationAgent;
import jfuzzyprincepless.zarchive.algorithm.structure.forcnstr.IForConstruction;
import jfuzzyprincepless.zarchive.algorithm.structure.forcnstr.fuzzyfor.IFuzzyForConstruction;
import jfuzzyprincepless.zarchive.negotiation.services.IExecuteForService;
import jfuzzyprincepless.negotiation.INegotiationContext;

public class FakeForAgetn<E> extends BaseNegotiationAgent {
	private StringBuilder sb;
	private String cmd;

	public FakeForAgetn(StringBuilder sb, String cmd) {
		super();
		this.sb = sb;
		this.cmd = cmd;
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean negotiate(INegotiationContext context) {
		IExecuteForService<E> forServ =
			context.getService(IExecuteForService.class);
		sb.append(cmd).append(forServ.getCurrentElem());

		IForConstruction<E> forConstr =
			forServ.getForConstruction();
		if (forConstr instanceof IFuzzyForConstruction<?>) {
			IFuzzyForConstruction<E> fforConstr =
				(IFuzzyForConstruction<E>)forConstr;
			double membershipDegree = fforConstr.getFuzzyForSet()
				.getMembershipDegree(forServ.getCurrentElem());
			sb.append("mem").append(membershipDegree);
		}

		return super.negotiate(context);
	}
}
